
local Animal = {}  -- name

function Animal:new()
	local animal = {}
	self.__index = self;
	setmetatable(animal, self)
	return animal
end

function Animal:setName(name)
	self.name = name
end


-- return Animal;

function testAnimal ()
	print 'testAnimal'
	local dog = Animal:new()
	print(dog)
	dog:setName('foo')
	print(dog['name'])
end

-- testAnimal()


-- inherit
local Cat = Animal:new()
function Cat:new()
	local cat = {}
	print(self)
	for k,v in pairs(self) do print(k,v) end
	self.__index = self
	return setmetatable(cat,self)
end

function Cat:sound()
	print(self.name .. ', miao')
end

local cat = Cat:new()
cat:setName('kitty')
cat:sound()
print(cat)
for k,v in pairs(cat) do print(k,v) end